package com.itheima.job.test03;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class UDPReceiver {
    public static void main(String[] args) throws IOException {
        DatagramSocket ds = new DatagramSocket(8888);

        byte[] bytes = new byte[1024];
        DatagramPacket dp = new DatagramPacket(bytes,bytes.length);
        ds.receive(dp);
        System.out.println(new String(bytes,0,dp.getLength()));

        byte[] bytes1 = "你好发送端".getBytes();
        DatagramPacket dp1 = new DatagramPacket(bytes1,bytes1.length,InetAddress.getByName("127.0.0.1"),12345);
        ds.send(dp1);
        ds.close();
    }
}

